package cn.zwx.business.order.remote;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

/**
 * @author zhangwenxue
 */
public class RpcProxyServer {

    static ThreadFactory defaultThreadFactory  = new DefaultThreadFactory("socketBioServerThreadPoo-");
    static ExecutorService executorService = new ThreadPoolExecutor(8, 8,
            30L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(200),defaultThreadFactory,new ThreadPoolExecutor.CallerRunsPolicy());


    /**
     * 发布本地应用
     * @param port 端口
     */
    public void  publisher(int port){
        ServerSocket serverSocket;
        try {
            serverSocket = new ServerSocket(port);
            while (true){
                // 监听客户端来请求
                Socket clientAccept = serverSocket.accept();
                // 使用线程池去处理
                executorService.submit(new ProcessorHandler(clientAccept));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
